use sea_orm::{Database, DatabaseConnection};
use serde::{Deserialize, Serialize};


#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Config {
    pub host: String,
    pub port: u16,
    pub username: String,
    pub password: String,
    pub dbname: String,
}

pub async fn connect(config: &Config) -> Result<DatabaseConnection, sea_orm::DbErr> {
    Database::connect(format!(
        "mysql://{}:{}@{}:{}/{}",
        config.username, config.password, config.host, config.port, config.dbname
    ))
        .await
}